<template>
  <ul>
    <h1>店铺信息</h1>
    <li>
      <span>店铺名字：</span>
      <span>{{shopData.name}}</span>
    </li>
    <li>
      <span>店铺简介：</span>
      <span>{{shopData.desc}}</span>
    </li>
    <li>
      <span>店铺类型：</span>
      <span>{{shopData.Type}}</span>
    </li>
    <li>
      <span>店铺地址：</span>
      <span>{{shopData.address}}</span>
    </li>
    <li>
      <span>注册资金：</span>
      <span>{{shopData.registerMoney}}</span>
    </li>
    <li>
      <span>审核状态：</span>
      <template v-if="shopData.state==1">
        <span>未审核</span>
      </template>
      <template v-if="shopData.state==2">
        <span>审核成功</span>
      </template>
      <template v-if="shopData.state==3">
        <span>审核失败</span>
      </template>
    </li>
    <li>
      <el-button type="primary" @click="update">信息修改</el-button>
      <el-button type="danger" @click="dialogVisible = true">关闭店铺</el-button>
      <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
        <span>确定要关闭店铺吗？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="danger" @click="dialogVisible = false , close()">确 定</el-button>
        </span>
      </el-dialog>
    </li>
  </ul>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions } = createNamespacedHelpers("shop");
export default {
  data() {
    return {
      merchant: "",
      shopData: {},
      dialogVisible: false
    };
  },
  methods: {
    ...mapActions(["getMerchantAsync", "updateShopAsync",'deleteShopAsync']),
    update() {
      this.$router.push(`/merchant/merchantUpdate`);
    },
    async close() {
      let data = await this.deleteShopAsync(this.shopData);
      if(data.data){
        this.$alert("店铺关闭成功！", "提示消息", {
          confirmButtonText: "确定",
          callback: action => {
            this.$router.push("/merchant/MerchantAdd");
          }
        });
      }
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    }
  },
  created() {
    this.merchant = sessionStorage.getItem("userName");
  },
  watch: {
    async merchant() {
      let data = await this.getMerchantAsync(this.merchant);
      if (data) {
        this.shopData = data;
      } else {
        this.$alert("你还没有店铺，点击确定去开店！", "提示消息", {
          confirmButtonText: "确定",
          callback: action => {
            this.$router.push("/merchant/MerchantAdd");
          }
        });
      }
    }
  }
};
</script>

<style scoped>
ul {
  list-style: none;
}
li {
  margin: 36px 0;
}
</style>